package com.woniu.controller;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.controller.form.FindByStationIdAndMonthForm;
import com.woniu.controller.form.FindByStationIdAndMonthPageForm;
import com.woniu.model.MonthTotal;
import com.woniu.model.Result;
import com.woniu.service.MonthTotalService;
import com.woniu.service.param.FindByStationIdAndMonthPageParam;
import com.woniu.service.param.FindByStationIdAndMonthParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  仓库统计相关接口
 * </p>
 *
 * @author 吴彦祖
 * @since 2024年05月23日
 */
@RestController
@Api(tags = "仓库统计相关接口")
@RequestMapping("/monthTotal")
public class MonthTotalController {
    @Resource
    private MonthTotalService monthTotalService;
    /**
     *查询仓库某月统计信息List
     * @param form 查询仓库某月统计信息form
     * @return 仓库某月统计信息List
     */
    @PostMapping("/findByStationIdAndMonth")
    @ApiOperation("根据站点id查询仓库某月统计信息List")
    public Result<List<MonthTotal>> findByStationIdAndMonth(@RequestBody FindByStationIdAndMonthForm form) throws Exception {
        List<MonthTotal> MonthTotals = monthTotalService.findByStationIdAndMonth(BeanUtil.toBean(form, FindByStationIdAndMonthParam.class));
        return Result.newListInstance(MonthTotal.class).setCode(200).setData(MonthTotals).setMessage("根据站点id和月份查询仓库统计信息成功!");
    }

    /**
     *查询仓库某月统计信息Page
     * @param form 查询仓库某月统计信息form
     * @return 仓库某月统计信息Page
     */
    @PostMapping("/findByStationIdAndMonthPage")
    @ApiOperation("根据站点id查询仓库某月统计信息Page")
    public Result<Page<MonthTotal>> findByStationIdAndMonthPage(@RequestBody FindByStationIdAndMonthPageForm form) throws Exception {
        Page<MonthTotal> MonthTotals = monthTotalService.findByStationIdAndMonthPage(BeanUtil.toBean(form, FindByStationIdAndMonthPageParam.class));
        return Result.newPageInstance(MonthTotal.class).setCode(200).setData(MonthTotals).setMessage("根据站点id和月份查询仓库统计信息成功!");
    }

    /**
     *按照月份查询站点统计信息List
     * @param id 站点id
     * @return 按照月份查询站点统计信息List
     */
    @GetMapping("/findByMonth/{id}")
    @ApiOperation("按照月份查询所有站点今年统计信息List")
    public Result<List<MonthTotal>> findByMonth(@PathVariable("id") Integer id) throws Exception {
        List<MonthTotal> MonthTotals = monthTotalService.findByMonth(id);
        return Result.newListInstance(MonthTotal.class).setCode(200).setData(MonthTotals).setMessage("按照月份查询站点统计信息List成功!");
    }

    /**
     *按照月份查询站点统计信息Page
     * @param id 站点id
     * @return 按照月份查询站点统计信息Page
     */
    @GetMapping("/findByMonthPage")
    @ApiOperation("按照月份查询所有站点今年统计信息Page")
    public Result<Page<MonthTotal>> findByMonthPage(@RequestParam("id") Integer id,@RequestParam("pageNum") Integer pageNum,@RequestParam("pageSize") Integer pageSize) throws Exception {
        Page<MonthTotal> MonthTotals = monthTotalService.findByMonthPage(id,pageNum,pageSize);
        return Result.newPageInstance(MonthTotal.class).setCode(200).setData(MonthTotals).setMessage("按照月份查询站点统计信息List成功!");
    }

}

